package utill;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Factory.beanFactory;
import domain.*;
public class ResultUtil {
    private ResultUtil(){
    }


    public static List<customer> PackingCustomer(ResultSet rs){
        List<customer> customerList =new ArrayList<>();
       if(rs==null) return  customerList;
        try {
            while (rs.next()) {
                customer c = beanFactory.getCustomer();
                c.setCustomerId(rs.getInt("customerId"));
                c.setCustomerName(rs.getString("customerName"));
                c.setCustomerPasword(rs.getString("customerPasword"));
                c.setCustomerMoney(rs.getString("CustomerMoney"));
                customerList.add(c);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }


        return  customerList;
    }


    public  static  List<flower> PackingFlower(ResultSet rs){
         List<flower> flowerList=new ArrayList<>();
         if(rs==null) return  flowerList;
         try{
             while (rs.next()){
                 flower f= beanFactory.getFlower();
                 f.setFlowerId(rs.getInt("flowerId"));
                 f.setFlowerType(rs.getString("flowerType"));
                 f.setFlowertotal(rs.getInt("flowertotal"));
                 f.setFlowerPrice(rs.getString("flowerPrice"));
                 f.setStoreId(rs.getInt("storeId"));
                 flowerList.add(f);
             }
         }catch (SQLException e){
             e.printStackTrace();
         }
         return  flowerList;
    }

    public  static  List<flowerstore> PackingFlowerStore(ResultSet rs){
        List<flowerstore> flowerstoreArrayList=new ArrayList<>();
        if(rs==null) return  flowerstoreArrayList;
        try{
            while (rs.next()){
                flowerstore f= beanFactory.getFlowerstore();
                f.setStoreId(rs.getInt("storeId"));
                f.setStoreName(rs.getString("storeName"));
                f.setStorePassword(rs.getString("storePassword"));
                f.setStoreIncome(rs.getString("storeIncome"));
                flowerstoreArrayList.add(f);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
        return  flowerstoreArrayList;
    }


    public  static  List<OrderResult> PackingOrderResult(ResultSet rs){
        List<OrderResult> orderResultList=new ArrayList<>();
        if(rs==null) return orderResultList;
        try{
            while (rs.next()){
                OrderResult o=beanFactory.getOrderResult();
                o.setUserName(rs.getString("customerName"));
                o.setFlowerType(rs.getString("flowertype"));
                o.setFlowertotal(rs.getInt("flowernumber"));
                o.setFlowerPrice(rs.getString("totalprice"));
                o.setFlowerBuyTime(rs.getString("orderdate"));
                orderResultList.add(o);
            }

        }catch ( SQLException e){
            e.printStackTrace();
        }

        return  orderResultList;
    }

    public  static  List<CorderResult> PackingCorderResult(ResultSet rs){
        List<CorderResult>  corderResultList=new ArrayList<>();
        if(rs==null) return corderResultList;
        try{
            while (rs.next()){
                CorderResult o=beanFactory.getCorderResult();
                o.setStoreName(rs.getString("storeName"));
                o.setFlowerType(rs.getString("flowertype"));
                o.setFlowertotal(rs.getInt("flowernumber"));
                o.setFlowerPrice(rs.getString("totalprice"));
                o.setFlowerBuyTime(rs.getString("orderdate"));
                corderResultList.add(o);
            }

        }catch ( SQLException e){
            e.printStackTrace();
        }

        return  corderResultList;
    }
}
